<template>
	<view>
		<view class="cart" v-if="cart.length >0">
			<!-- 收货地址区域 -->
			<my-address></my-address>
			<!-- 商品列表区域 -->
			<view class="list">
				<view class="title">
					<uni-icons class="myicon" type="shop" size="18"></uni-icons>
					购物车
				</view>
				<!-- 渲染商品列表 -->
				<view class="goods-box">
					<uni-swipe-action>
						<uni-swipe-action-item @click="del(item)" :right-options="options" v-for="(item,index) in cart"
							:key="index">
							<my-goods @num-change="numChange" @radio-change="radiochange" :showNum="true"
								:showRadio="true" :item="item"></my-goods>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
			</view>
			<!-- 结算区域 -->
			<my-total></my-total>
		</view>
		<view class="kong" v-else>
			<image src="../../static/cart_empty@2x.png" mode=""></image>
			<text>空空如也~</text>
		</view>
	</view>
</template>

<script>
	import mymixins from '../../mixins/mymixins.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		mixins: [mymixins],
		computed: {
			...mapState('cart', ['cart'])
		},
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#ffc0cb'
					}
				}]
			};
		},
		methods: {
			...mapMutations('cart', ['changStatus', 'changNum', 'delGoods']),
			// 删除购物车中的商品
			del(item) {
				this.delGoods(item.goods_id)
			},
			// 点击加减修改数字
			numChange(e) {
				// console.log('numChange', e)
				this.changNum(e)
			},
			// 修改单选的状态
			radiochange(e) {
				// console.log('radiochange', e)
				this.changStatus(e)
			}
		}
	}
</script>

<style lang="scss">
	.cart {
		margin-bottom: 120rpx;

		.goods-list {
			.top {
				height: 100rpx;
				line-height: 100rpx;
				border-bottom: 1px solid #eff0ef;
				padding-left: 10rpx;

				text {
					margin-left: 20rpx;
				}
			}
		}
	}

	.kong {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 200rpx;

		image {
			width: 200rpx;
			height: 200rpx;
		}

		text {
			font-size: 12px;
			color: #858585;
			margin-top: 20rpx;
		}
	}
</style>
